//
//  TitleCell.swift
//  FeastBooking
//
//  Created by Imon on 2017/9/3.
//  Copyright © 2017年 Imon. All rights reserved.
//

import UIKit

class TitleCell: UICollectionViewCell {
    
    let label: UILabel = {
        let label = UILabel()
        label.font = AppBoldFont()
        return label
    }()
    
    var text: String? {
        get {
            return label.text
        }
        set {
            label.text = newValue
        }
    }
    
    override init(frame: CGRect) {
        super.init(frame: frame)
        contentView.addSubview(label)
    }
    
    required init?(coder aDecoder: NSCoder) {
        fatalError("init(coder:) has not been implemented")
    }
    
    override func layoutSubviews() {
        let textMaxSize = CGSize(width: bounds.width, height: 20)
        let labelWidth = TextSize.textSize(text: label.text!, font: label.font, maxSize: textMaxSize).width
        label.frame = UIEdgeInsetsInsetRect(bounds, UIEdgeInsetsMake(5, 15, 5, bounds.width - 15 - labelWidth))
    }
}
